﻿using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using LS.Screening.AvaloniaApp.ViewModels;
using LS.Screening.AvaloniaApp.Views;
using LS.Screening.UI.Common.Mvvm;
using Microsoft.Extensions.DependencyInjection;

namespace LS.Screening.AvaloniaApp;

public partial class App :CommonApplication
{
    /// <summary>
    /// 初始化
    /// </summary>
    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
    }

    /// <summary>
    /// App初始化完成后触发
    /// </summary>
    public override void OnFrameworkInitializationCompleted()
    {
        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
        {
            desktop.MainWindow = new LoginWindow();
            SetCurrentWidow(desktop.MainWindow);
        }
        base.OnFrameworkInitializationCompleted();
    }

    /// <summary>
    /// 服务注入
    /// </summary>
    public override void RegisterServices()
    {
        base.RegisterServices();
        if (Services == null)
            Services = new ServiceCollection();

        Services.AddSingleton<Application.ITestAppService, Application.TestAppService>();
        Services.AddSingleton<LoginWindowViewModel>();
        Services.AddSingleton<MainWindowViewModel>();
        Services.AddSingleton<AboutViewModel>();
        Services.AddSingleton<HeaderViewModel>();
        Services.AddSingleton<MainViewModel>();
        Services.AddSingleton<MenuViewModel>();

        ServiceProvider = Services.BuildServiceProvider();
    }
}
